import axios from "axios"
import NProgress from 'nprogress'
import 'nprogress/nprogress.css' 
axios.defaults.baseURL = "http://www.liulongbin.top:3005/"

axios.interceptors.request.use(config => {
   NProgress.start()
  config.headers.Authorization = window.sessionStorage.getItem('token')

  return config
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
})
axios.interceptors.response.use(config => {
    NProgress.done()
    return config})
    // 获取商品数据列表
export let shopget = async (number) => {
        return axios.get(`/api/getgoods?pageindex=${number}`)
}
export let shopdetailsget = async (id) => {
  return axios.get(`/api/goods/getdesc/${id}`)
}
// 获取购物车数据
export let shopcarget = async (ids) => {
  return axios.get(`/api/goods/getshopcarlist/${ids}`)
}
export let shopinfoget = async (id) => {
  return axios.get(`/api/goods/getinfo/${id}`)
}
export let shopimg = async (id) => {
  return axios.get(`/api/getthumimages/${id}`)
}
// 商品评论
export let postcom = async (qq) => {
  return axios.post(`/api/postcomment/${qq.id}`,{content:qq.content})}
// import axios from 'axios'

// 获取图片分类列表
export const getImgsClassify = () => {
    return axios.get('/api/getimgcategory')
}

// 获取图片列表数据
export const getImgsList = (id) => {
    return axios.get(`/api/getimages/${id}`)
}

// 获取图片详情
export const getImgsDetail = (id) => {
    return axios.get(`/api/getimageInfo/${id}`)
}

// 图片详情中的缩略数组
export const getImgsArr = (id) => {
    return axios.get(`/api/getthumimages/${id}`)
}

// 获取评论
export const getCommentList = (params) => {
    return axios.get(`/api/getcomments/${params.artid}?pageindex=${params.pageindex}`, params)
}

// 发布评论
export const postComment = (params) => {
    return axios.post(`/api/postcomment/${params.artid}`,params)
}